$(function(){
	childrenCompany();
	search();
});

var childrenCompany=function(){
	$.ajax({
		url : contextPath+ 'user/company/childrencompany',
		type : 'POST',
		success : function(list) {
			if(list!=null && list.length>0){
				$("#companyId").empty();
				var option="<option value ='0' >全部单位</option>";
				for(var i=0;i<list.length;i++){
					var company = list[i];
					option +="<option value='"+company.companyId+"'>"+company.companyName+"</option>";
				}
				$("#companyId").append(option);
			}
		}
	});
};

function search(){
	var companyId = $('#companyId').val();
	var levelname = $('#levelname').val();
	$.ajax({
		url : contextPath+ 'user/vzdy/list',
		data : {
			companyId : companyId,
			levelname :levelname
		},
		type : 'POST',
		success : function(list) {
			$("#content").empty();
			if(list!=null && list.length>0){
				var count =0;
				for(var i=0;i<list.length;i++){
					count += list[i].number;
					var div = '<div class="pwsj_right_czrz_cont">';
					div += '<ul class="czrz_cont_ul">';
					div += '<li class="number" style="width: 30%">'+list[i].companys.companyName+'</li>';
					div += '<li class="time" style="width: 25%">'+list[i].levename+'</li>';
					div += '<li class="operation" style="width: 30%">'+list[i].devicetypename+'</li>';
					div += '<li class="username" style="width: 14%;border-right:none;">'+list[i].number+'</li>';
					div += '</ul>';
					div += '</div>';
					$("#content").append(div);
				}
				var end = '<div class="pwsj_right_czrz_cont">';
				end += '<ul class="czrz_cont_ul">';
				end += '<li class="number" style="width: 30%">合计</li>';
				end += '<li class="time" style="width: 25%"></li>';
				end += '<li class="operation" style="width: 30%"></li>';
				end += '<li class="username" style="width: 14%;border-right:none;">'+count+'</li>';
				end += '</ul>';
				end += '</div>';
				$("#content").append(end);
			}
		}
	});
}

function exportexcle(){
	var companyId = $('#companyId').val();
	var levelname = $('#levelname').val();
	if(confirm("确定导出对应模板数据吗？")){
		$("#exportimg").show();
		$.ajax({
			url : contextPath+ 'user/excel/vzdylist',
			data : {
				companyId : companyId,
				levelname : levelname
			},
			type : 'POST',
			success : function(data) {
				$("#exportimg").hide();
				var uploadurl = basePath + data.msgDesc;
				//alert(uploadurl);
				if(data.opResult == "0")
					window.location.href = uploadurl;
				else
					alert(data.msgDesc);
			}
		});
	}
}
